package com.swsm.controller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.swsm.Constant;
import com.swsm.model.bean.B2SPrizePageBean;
import com.swsm.model.bean.B2SPrizeReviewBean;
import com.swsm.service.PrizeService;

@Controller
public class PrizeController {
	
	private Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private PrizeService service;
	
	@RequestMapping("/award.html")
	public String goToAward() {
		return "Award";
	}
	
	@ResponseBody
	@RequestMapping("/t/prizeReview")
	public String prizeReview(B2SPrizeReviewBean bean) {
		logger.info("=====> 审核获奖信息");
		JSONObject result = new JSONObject();

		try {
			service.prizeReview(bean);
			result.put("status", Constant.INSTANSE.OK);
			result.put("msg", "审核获奖信息成功！");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.put("status", Constant.INSTANSE.SERVSER_ERROR);
			result.put("msg", "服务器内部错误！");
		}
		result.put("time", new Date());
		return result.toJSONString();
	}
	
	@ResponseBody
	@RequestMapping("/t/getAllPrize")
	public String getAllPrize(B2SPrizePageBean bean) {
		logger.info("=====> 获取所有获奖信息");
		JSONObject result = new JSONObject();
		
		try {
			result.put("status", Constant.INSTANSE.OK);
			result.put("data", service.getAllPrize(bean));
			result.put("msg", "获取所有获奖信息成功！");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.put("status", Constant.INSTANSE.SERVSER_ERROR);
			result.put("msg", "服务器内部错误！");
		}
		result.put("time", new Date());
		return result.toJSONString();
	}

}
